Skip to content

Conversation

@i-n-g-m-a-r
Copy link
Contributor

@fuelen
Copy link
Contributor

fuelen commented Mar 14, 2025

Could you check these places?

* Query string: <%= @conn.query_string %>
### Headers
<%= for {key, value} <- Enum.sort(@conn.req_headers) do %>
* <%= key %>: <%= value %><% end %>

seems like query_string and headers may be vulnerable as well

@i-n-g-m-a-r
Copy link
Contributor Author

@fuelen nice catch, tnx :)

@SteffenDE
Copy link
Contributor

I think the correct approach here is to just escape the whole textarea content:

diff --git a/lib/plug/debugger.ex b/lib/plug/debugger.ex
index 1974db6..4f69d7b 100644
--- a/lib/plug/debugger.ex
+++ b/lib/plug/debugger.ex
@@ -234,7 +234,7 @@ defmodule Plug.Debugger do
         Keyword.merge(assigns,
           conn: conn,
           message: maybe_autolink(message),
-          markdown: markdown,
+          markdown: h(markdown),
           style: style,
           banner: banner,
           actions: actions,
diff --git a/lib/plug/templates/debugger.html.eex b/lib/plug/templates/debugger.html.eex
index fdc8f20..94242a1 100644
--- a/lib/plug/templates/debugger.html.eex
+++ b/lib/plug/templates/debugger.html.eex
@@ -1057,7 +1057,7 @@
         function copyToClipboard () {
           if(navigator.clipboard) {
             // For those working on localhost or HTTPS
-            navigator.clipboard.writeText($copy.innerHTML).then(copiedClipboard).catch(() => {})
+            navigator.clipboard.writeText($copy.textContent).then(copiedClipboard).catch(() => {})
           } else {
             // For those working on HTTP
             $copy.select()

The copy button should use textContent instead of innerHTML.

Not sure if escaping in the markdown template itself is necessary. I guess that depends on who is rendering the markdown, but that's typically not a browser.

Copy link
Contributor

@SteffenDE SteffenDE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @josevalim

@josevalim josevalim merged commit 361b7fb into elixir-plug:main Mar 14, 2025
2 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

josevalim pushed a commit that referenced this pull request Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants